package com.ruoyi.quartz.task;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BacklogStatus;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.enums.TenantUsedType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.framework.util.ShiroUtils;
import com.ruoyi.common.enums.TenantStatus;
import com.ruoyi.system.domain.SysTenant;
import com.ruoyi.system.domain.SysTenantBacklog;
import com.ruoyi.system.service.ISysTenantBacklogService;
import com.ruoyi.system.service.ISysTenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 更新收租列表 (每月更新一次)
 *
 * @author dhk
 */

@Component("backlogTask")
public class BacklogTask {

    @Autowired
    private ISysTenantBacklogService backlogService;

    @Autowired
    private ISysTenantService tenantService;

    //每月更新一次收租列表
    @Log(title = "每月更收租列表定时任务执行", businessType = BusinessType.INSERT)
    public void insertBacklogForMonth(){
        SysTenant sysTenant = new SysTenant();
        sysTenant.setTenantStatus(TenantStatus.LIVEING.getCode());
        List<SysTenant> tenantList = tenantService.selectSysTenantList(sysTenant);
        for (SysTenant tenant : tenantList) {
            SysTenantBacklog backlog = new SysTenantBacklog();
            backlog.setTenantId(tenant.getTenantId());
            backlog.setBacklogStatus(BacklogStatus.WAIT.getCode());
            backlog.setBacklogTime(DateUtils.dateTimeNow(DateUtils.YYYY_MM));
            backlogService.insertSysTenantBacklog(backlog);
        }
    }
}
